<%--
  Created by IntelliJ IDEA.
  User: 风间天道
  Date: 2019/6/1
  Time: 13:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>用户信息</title>
    <script>
        var a = "${ctx}"
    </script>
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css">
    <script src="${ctx}/layui/layui.js"></script>
    <script src="${ctx}/js/jquery-1.11.0.min.js"></script>
</head>
<body>
<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="barDemo">

    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="ignore">删除</a>
</script>
<script src="${ctx}/layui/layui.js"></script>

<script>
    var s;
    $(function () {
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#test'
                , url: a + '/selectprize'
                , cols: [[
                    {field: 'id', width: 80, title: 'ID', sort: true}
                    , {field: 'time', width: 150, title: '申请时间'}
                    , {field: 'user.nickname', width: 80, title: '申请人',templet: '<div>{{d.user.nickname}}</div>',sort: true}
                    , {field: 'prize.name', width: 100, title: '奖品名',templet: '<div>{{d.prize.name}}</div>' }
                    , {field: 'finishtime', title: '交易完成时间', minWidth: 150}
                    , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150}
                ]]
                , page: true
            });
            table.on('tool(test)', function (obj) {

                //console.log(obj)
                if (obj.event === 'ignore') {
                    layer.confirm('真的删除该条记录么', function (index) {
                        //向服务端发送删除指令
                        $.ajax({
                            type: "POST",
                            url: a + '/delprize',
                            data: {id: obj.data.id},
                            dataType: "json",
                            success: function () {
                                obj.del();
                                layer.close(index);
                                layer.msg("删除成功", {icon: 6})
                            },
                            error: function () {
                                layer.msg("删除失败", {icon: 5});
                            }
                        });
                    });
                }
            });
        });
    });

</script>
</div>
</body>
</html>
